/**
 * 专门为login服务的action
 * @param {*} data 
 * @returns 
 */
import { getInfo } from "@/api/user"
import { SAVE_Token, SAVE_USER_INFO , LOYOUT} from "../actionType"

export const saveTokenAction = (data) => ({type: SAVE_Token, data})
export const saveUserInfoAction = (data) => ({type: SAVE_USER_INFO, data})
export const logoutAction = () => ({type: LOYOUT})

export const getUserInfo = () => async dispatch => {
  try{
    const res  = await getInfo()
    if(res.code === 200 ) {
      delete res.code
      delete res.msg
      await dispatch(saveUserInfoAction(res))
    } 
  }catch(err) {
    console.log(err)
  }
}

